package com.sgb.goods.viewmodel.inquiry;

import androidx.lifecycle.MutableLiveData;

import com.sgb.goods.api.GoodsCallBack;
import com.sgb.goods.api.GoodsNet;
import com.sgb.goods.entity.AttributeViewEntity;
import com.sgb.goods.entity.BrandEntity;
import com.sgb.goods.entity.CommonStAttrEntity;
import com.sgb.goods.entity.GoodsUnitEntity;
import com.sgb.goods.entity.MenuEntity1;
import com.sgb.goods.utils.base.viewmodel.BaseViewModel;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;

import java.util.List;

/**
 * 描述：询价-新增采购品
 *
 * @author qiangHeNoo
 * <p>
 * 时间：2021.12.10
 */
public class NewPurchasesModel extends BaseViewModel {
    /**
     * 商品三级分类
     */
    public MutableLiveData<List<MenuEntity1<MenuEntity1<MenuEntity1>>>> menuEntity = new MutableLiveData<>();
    /**
     * 品牌
     */
    public MutableLiveData<List<BrandEntity>> brandEntity = new MutableLiveData<>();
    /**
     * 商砼属性
     */
    public MutableLiveData<List<CommonStAttrEntity>> commonStAttrEntity = new MutableLiveData<>();
    /**
     * 商品单位
     */
    public MutableLiveData<List<GoodsUnitEntity>> unitEntity = new MutableLiveData<>();
    /**
     * 属性是否可见
     */
    public MutableLiveData<Boolean> isAttributeVisibility = new MutableLiveData<>();
    /**
     * 商品属性
     */
    public MutableLiveData<List<AttributeViewEntity>> attributeViewEntity = new MutableLiveData<>();

    /**
     * 获取商品属性信息
     */
    public void getAttribute(String id, boolean isShowAttribute) {
        showLoading();
        GoodsNet.getInstance().getGoodsApi().getAttribute(id).enqueue(new ICallBack<BaseEntity<List<AttributeViewEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<AttributeViewEntity>> data) {
                List<AttributeViewEntity> dataList = data.getData();
                if (isShowAttribute && (dataList == null || dataList.size() == 0)) {
                    isAttributeVisibility.postValue(false);
                } else {
                    isAttributeVisibility.postValue(true);
                    if (isShowAttribute) {
                        return;
                    }
                    attributeViewEntity.postValue(data.getData());
                }
            }
        });
    }

    /**
     * 获取商砼属性信息
     */
    public void getStAttribute() {
        showLoading();
        GoodsNet.getInstance().getGoodsApi().getStAttribute().enqueue(new GoodsCallBack<BaseEntity<List<CommonStAttrEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<CommonStAttrEntity>> data) {
                if (data == null || data.getData() == null) {
                    return;
                }
                commonStAttrEntity.postValue(data.getData());
            }
        });
    }

    /**
     * 获取价格单位
     */
    public void getUnitList(String text) {
        showLoading();
        GoodsNet.getInstance().getGoodsApi().unitList(text).enqueue(new GoodsCallBack<BaseEntity<List<GoodsUnitEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<GoodsUnitEntity>> data) {
                if (data == null || data.getData() == null) {
                    return;
                }
                unitEntity.postValue(data.getData());
            }
        });
    }

    /**
     * 获取品牌信息
     */
    public void getBrand(String id, String text) {
        showLoading();
        GoodsNet.getInstance().getGoodsApi().brandList(id, text).enqueue(new GoodsCallBack<BaseEntity<List<BrandEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<BrandEntity>> data) {
                if (data == null || data.getData() == null) {
                    return;
                }
                brandEntity.postValue(data.getData());
            }
        });
    }

    /**
     * 获取商品分类信息
     */
    public void getGoodsCategory() {
        showLoading();
        GoodsNet.getInstance().getGoodsApi().goodsCategory().enqueue(new GoodsCallBack<BaseEntity<List<MenuEntity1<MenuEntity1<MenuEntity1>>>>>() {
            @Override
            public void onSuccess(BaseEntity<List<MenuEntity1<MenuEntity1<MenuEntity1>>>> data) {
                if (data == null || data.getData() == null) {
                    return;
                }
                menuEntity.postValue(data.getData());
            }
        });
    }
}
